/*
 *                       COPYRIGHT NOTICE
 *
 *           This code is copyright protected by Freedom Inc.
 *
 *               2001-2012 All Rights Are Reserved
 */
package com.freedom.oldsong.json;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

/**
 * @author steven.wang
 *
 */
public final class JSONWriteUtils {
	/**
	 * 
	 */
	public static final String JSON_CONTENT_TYPE = "text/json";
	
	private JSONWriteUtils(){
		
	}

	/**
	 * 
	 * @param json
	 */
	public static void sendResult(JSONObject json){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType(JSON_CONTENT_TYPE);
		try {
			PrintWriter out = response.getWriter();
			out.println(json);
		} catch (IOException ioe) {
			throw new RuntimeException(ioe);
		}
	}
	
	/**
	 * 
	 * @param HashMap
	 */
	public static void sendResult(Map map){
		sendResult(new JSONObject(map));
	}
}
